package barratt;

import java.util.SortedMap;
import java.util.TreeMap;

/**
 * scale the BarrattInterferenceModel from 8k to 159k with 10k increments and
 * report the MSE across the range of interference parameter k (0.0 < k < 1.0).
 *
 * @author Susanta Tewari
 *
 */
public class FitBarrattInterferenceModel {

    @SuppressWarnings("unchecked")
    public static void main(final String[] args) {}

    public void run(final BarrattModelData modelData) {

        for (double xScale = 8000; xScale < 169000; xScale += 10000) {

            System.out.println("BarrattInterferenceModel for xScale: " + xScale);

            final BarrattInterferenceModel barrattModel = new BarrattInterferenceModel(modelData);

            barrattModel.setXScale(xScale);

            final SortedMap mseMap = new TreeMap();

            for (int i = 0; i < 11; i++) {

                final double k                                    = 0.1 * (i);
                final BarrattModelEstimator barrattModelEstimator = new BarrattModelEstimator(k);

                barrattModel.setModelEstimator(barrattModelEstimator);

                final double mse = barrattModel.getMSE();

                mseMap.put(mse, k);
            }

            System.out.println(mseMap);
            System.out.println("");
        }


        // run for  a specific k
//      BarrattModelEstimator barrattModelEstimator;
//      BarrattInterferenceModel barratModel = new BarrattInterferenceModel();
//      double k = 1.0;
//      barrattModelEstimator = new BarrattModelEstimator(k);
//      barratModel.setModelEstimator(barrattModelEstimator);
//      barratModel.runModel();
//
//      System.out.println("Best Mapping function: k :" + k);
//      System.out.println("observed estimated observedX ");
//      Record[] records = barratModel.getModelData().getRecords();
//      for (Record record : records) {
//              double observed = record.getData()[0].getValue();
//              double observedX = record.getData()[1].getValue();
//              double estimated = record.getData()[0].getEstimatedValue();
//              System.out.println(observed + "  " + estimated + "  " + observedX);
//      }
    }
}
